<template>
  <div id="" class="activityItem" @click="toDetail(matchInfo.id)">
    <span class="activityImg">
      <img :src="imgUrlLink(matchInfo.themeIcon)" alt="">
      <em>{{createTime(matchInfo.createTime)}}</em>
    </span>
    <div class="activityDiv">
      <div class="activityTit">
        <h3>{{matchInfo.title}}</h3>
        <span class="start" v-if="skillType==3">{{matchStatus2()}}</span><!-- 找赛事 -->
        <span :class="{'start':matchInfo.status_!=1}" v-else>{{matchStatus()}}</span>

      </div>
      <div class="">
        <p style="margin-bottom:6px;">
          <img src="@/assets/activityImage/time_green3.png" alt="" width="15">
          <!-- 2018-02-06 10:30:00 -->
          <!-- 活动开始时间 -->
          {{matchInfo.startBegin}}
        </p>
        <p>
          <img src="@/assets/activityImage/add_blue3.png" alt="" width="15">
          {{matchInfo.activityAddr}}
        </p>
      </div>
      <div class="" style="font-size:12px; color:#999;">
        <p>报名截止:{{matchInfo.enrollEnd}}</p>
        <p>报名人数:{{matchInfo.activityNo}} 收费 &yen;{{matchInfo.cost}}</p>
      </div>

    </div>
  </div>
</template>
<script>
export default {
  name: "",
  props: ['matchInfo','skillType'],
  data: () => ({

  }),
  methods: {
    matchStatus() {
      let status = this.matchInfo.status_;    //获取活动状态statu
      switch (status) {
        case 0:
          return '待审核';
          break;
        case 1:
          let todaytime = new Date().getTime();   //当前时间
          let enrollBegin = new Date(this.matchInfo.enrollBegin).getTime();   //报名开始时间
          let enrollEnd = new Date(this.matchInfo.enrollEnd).getTime();       //报名结束时间
          let startBegin = new Date(this.matchInfo.startBegin).getTime();     //活动开始时间
          let startEnd = new Date(this.matchInfo.startEnd).getTime();         //活动结束时间
          if(todaytime>enrollBegin && todaytime<enrollEnd){
            return "报名中"
          }else if(todaytime>startBegin && todaytime<startEnd){
            return "已开始"
          }else{
            return '审核通过';
          }
          break;
        case 2:
          return '审核失败'
          break;
        default:

      }
    },
    // 找赛事——状态
    matchStatus2() {

        let todaytime = new Date().getTime();   //当前时间
        let enrollBegin = new Date(this.matchInfo.enrollBegin).getTime();   //报名开始时间
        let enrollEnd = new Date(this.matchInfo.enrollEnd).getTime();       //报名结束时间
        let startBegin = new Date(this.matchInfo.startBegin).getTime();     //活动开始时间
        let startEnd = new Date(this.matchInfo.startEnd).getTime();         //活动结束时间
        if(todaytime>enrollBegin && todaytime<enrollEnd){
          return "报名中"
        }else if(todaytime>startBegin && todaytime<startEnd){
          return "已开始"
        }else if(todaytime>enrollEnd && todaytime<startBegin){
          return '报名结束';
        }else if(todaytime>startEnd){
          return '已结束';
        }
    },
    createTime(time) {
      let todaytime = new Date();   //当前时间
      let createTime = new Date(time);
      console.log(todaytime.getTime());
      let desTime = todaytime.getTime()/1000 - createTime.getTime()/1000;
      if (desTime<60) {
        if(desTime<0) desTime = 1;
        return Math.floor(desTime)+'秒前';
      }else if (desTime<3600) {
        let mm = Math.floor(desTime/ 60 % 60);
        return mm + '分钟前'
      }else if (desTime<(3600*24)) {
        let hh = Math.floor(desTime/3600);
        return hh + '小时前'
      }else{
        let dd = Math.floor(desTime/(3600*24));
        return dd + '天前'
      }
    },
    // 图片地址拼接
    imgUrlLink(imgurl) {
      return this.$imgUrlLink(imgurl);
    },
    // 跳转到赛事详情
    toDetail(matchId) {
      this.$router.push({
        path:'/eventDetail',
        query:{matchId:matchId}
      })
    }
  },
  mounted() {
    //do something after mounting vue instance
    console.log(this.skillType);
  }
}
</script>
<style lang="scss" scoped>
.activityItem{
  @include flex;
  align-items: flex-start;
  background: white;
  margin-top: 10px;
  padding: 10px;
  .activityImg{
    width: 110px;
    height: 90px;
    position: relative;
    img{
      width: 100%; height: 100%;
    }
    em{
      position: absolute;
      bottom: 0;
      left: 0; right: 0;
      z-index: 2;
      background: rgba(0,0,0,0.3);
      color: white;
      text-align: right;
      padding: 2px 4px;
    }
  }
  .activityDiv{
    @include flexcell;
    margin-left: 10px;
    @include flex;
    align-items: flex-start;
    min-height: 80px;
    flex-direction: column;
    justify-content: space-between;
    .activityTit{
      @include flex;
      justify-content: space-between;
      margin-bottom: 6px;
      h3{
        width: 178px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      span{
        color: $blueColor;
        @include flexcell;
        &.start{
          color: $redColor;
          text-align: right;
        }
      }
    }
  }
}
</style>
